﻿using CPPEI.Coolzon.Configuration;
using CPPEI.Coolzon.Configuration.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UpdateServer
{
    [XConfigRoot("Environment")]
    public class CZEnvironment
    {
        private static CZEnvironment s_intance;
        public static CZEnvironment Intance
        {
            get
            {
                if (s_intance == null)
                {
                    s_intance = new CZEnvironment();
                }
                return s_intance;
            }
        }

        [XConfig("Host")]
        public ServiceConfig ServiceConfig { get; private set; }

        private static Version _version;
        public static Version Version
        {
            get
            {
                if (_version == null)
                {
                    _version = typeof(CZEnvironment).Assembly.GetName().Version;
                }
                return _version;
            }
        }

        public static string Version3
        {
            get
            {
                return Version.ToString(3);
            }
        }

        /// <summary>
        /// 获取程序的目录地址
        /// </summary>
        /// <returns></returns>
        public static string GetBaseDirectory()
        {
            return AppDomain.CurrentDomain.BaseDirectory;
        }

        /// <summary>
        /// 获取Environment配置信息的文件路径
        /// </summary>
        /// <returns></returns>
        public static string GetEnvironmentConfigFilePath()
        {
            return string.Format("{0}\\Config\\Environment.xml", 
                AppDomain.CurrentDomain.BaseDirectory);
        }

        /// <summary>
        /// 获得日志保存目录
        /// </summary>
        /// <returns></returns>
        public static string GetLogDirectory()
        {
            return string.Format("{0}\\Coolzon\\Logs\\v{1}\\UpdateServer\\",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3);
        }
    }
}
